﻿Public Class CSVImportForm
    'ファイル選択ボタン処理
    Private Sub btnChooseFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChooseFile.Click
        Try
            If csvOpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
                txtChooseFile.Text = csvOpenFileDialog.FileName
            End If

        Catch ex As Exception
            MessageCommon.showError(My.Resources.E_SYSTEM_FAIL)
        End Try
    End Sub
    '実行ボタン処理
    Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
        Try
            '選択ファイルチェック
            If String.IsNullOrEmpty(txtChooseFile.Text) Then
                MessageCommon.showError(My.Resources.E_CSV_NOT_SELECTED)
                Exit Sub
            ElseIf Not ".csv".Equals(System.IO.Path.GetExtension(txtChooseFile.Text).ToLower) Then
                MessageCommon.showError(My.Resources.E_CSV_FORMAT_INVALID)
                Exit Sub
            End If

            Dim resultInfo = New CSVDao.ImportResult
            'プログレスバー表示
            Dim csvCon = New CSVDao
            resultInfo = csvCon.readCSV(txtChooseFile.Text, Me.cbImportMethod.SelectedIndex)
            resultInfo.importTypeName = cbImportMethod.SelectedItem.ToString
            '取込結果画面遷移
            If resultInfo.allowFlg = True Then
                'DB登録
                csvCon.importM_USER(resultInfo)
                'Log書込み
                Dim log = New LogCommon
                log.writeLog("CSV取込", resultInfo.getInfo)
                '取込結果画面情報用意
                Dim resultForm = New CSVImportResultForm
                resultForm.resultInfo = resultInfo
                resultForm.ShowDialog()
                Me.Close()
            Else
                MessageCommon.showError("取込ファイルが異常です。取込ができません。")
                'Log書込み
                Dim log = New LogCommon
                log.writeLog("CSV取込", resultInfo.getInfo)
            End If
        Catch ex As Exception
            MessageCommon.showError(My.Resources.E_SYSTEM_FAIL)
        End Try
    End Sub

    Private Sub CSVImportForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Me.cbImportMethod.SelectedIndex = 3
        Catch ex As Exception
            MessageCommon.showError(My.Resources.E_SYSTEM_FAIL)
        End Try
    End Sub
End Class